﻿
@{
    ViewData["Title"] = "添加商品类型";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">
            <div class="layui-fluid">
                <div class="layui-card">
                    <div class="layui-card-body" style="padding-top: 40px;">
                        <div class="layui-carousel" id="stepForm" lay-filter="stepForm" style="margin: 0 auto;">
                            <div carousel-item>
                                @*添加商品类型 start *@
                                <div>
                                    <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">商品分类名称:</label>
                                            <div class="layui-input-block">
                                                <input type="text" name="catName" placeholder="请输入商品分类名称" class="layui-input" lay-verify="required" lay-reqtext="请填写商品分类">
                                            </div>
                                        </div>
                                        <div class="layui-form-item layui-form-text">
                                            <label class="layui-form-label">备注信息</label>
                                            <div class="layui-input-block">
                                                <textarea name="seoDes" class="layui-textarea" placeholder="请输入备注信息"></textarea>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block">
                                                <button class="layui-btn" lay-submit lay-filter="formStep">
                                                    &emsp;下一步&emsp;
                                                </button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                @*添加商品类型 end *@

                                @*确认商品 start *@
                                <div>
                                    <form class="layui-form" style="margin: 0 auto;max-width: 460px;padding-top: 40px;">
                                        <div class="layui-form-item">
                                            <label class="layui-form-label required">商品分类父级</label>
                                            <div class="layui-input-block">
                                                <select name="parentId" id="selectSM" lay-filter="aihao" lay-reqtext="请选择商品分类" lay-verify="required">
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <label class="layui-form-label">商品佣金比例:</label>
                                            <div class="layui-input-block">
                                                <input type="number" name="commissionRate" placeholder="请填写商品佣金比例" value="" class="layui-input" lay-verify="number" required>
                                            </div>
                                        </div>
                                        <div class="layui-form-item">
                                            <div class="layui-input-block">
                                                <button type="button" class="layui-btn layui-btn-primary pre">上一步</button>
                                                <button class="layui-btn" lay-submit lay-filter="formStep2">
                                                    &emsp;确认添加&emsp;
                                                </button>
                                            </div>
                                        </div>
                                    </form>
                                </div>
                                @*确认商品 end *@

                                @*完成添加 start *@
                                <div>
                                    <div style="text-align: center;margin-top: 90px;">
                                        <i class="layui-icon layui-circle"
                                           style="color: white;font-size:30px;font-weight:bold;background: #52C41A;padding: 20px;line-height: 80px;">&#xe605;</i>
                                        <div id="susses" style="font-size: 24px;color: #333;font-weight: 500;margin-top: 30px;">
                                           
                                        </div>
                                    </div>
                                    <div style="text-align: center;margin-top: 50px;">
                                        <button class="layui-btn next">再次添加</button>
                                        <button class="layui-btn layui-btn-primary">查看商品类型</button>
                                    </div>
                                </div>
                                @*完成添加 end *@

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['form', 'step'], function () {
            var $ = layui.$,
                form = layui.form,
                step = layui.step;
            form.render();
            step.render({
                elem: '#stepForm',
                filter: 'stepForm',
                width: '100%', //设置容器宽度
                stepWidth: '750px',
                height: '500px',
                stepItems: [{
                    title: '添加商品类型'
                }, {
                    title: '确认商品类型'
                }, {
                    title: '完成'
                }],

            });
            var Step;
            //下一步
            form.on('submit(formStep)', function (data) {
                step.next('#stepForm');
                Step = data;
                GetPrentdata();
                return false;
            });

            //确认添加
            form.on('submit(formStep2)', function (data) {
                step.next('#stepForm');
                var aikeApplet_Goods = {};
                aikeApplet_Goods = Object.assign({}, Step.field, data.field)
                AddGoodCong(aikeApplet_Goods);
                return false;
            });

            //上一步
            $('.pre').click(function () {
                step.pre('#stepForm');
            });

            //再次添加
            $('.next').click(function () {
                step.next('#stepForm');
            });
        })

        //获取商品父级信息
        function GetPrentdata() {
            $.ajax({
                type: 'post',
                url: '/GoodsConfigInfo/GoodsConfigInfo/GetParentInfomation',
                data: null,
                dataType: "json",
                success: function (data) {
                    if (data.code == 200) {
                        for (var i = 0; i < data.result.length; i++) {
                            $("#selectSM").append("<option value='" + data.result[i]["parentId"] + "'>" + data.result[i]["catName"]+"</option>");
                        }
                    }
                }, error: function (err) {
                    if (err.status == 500) {
                        $("#selectSM").append("<option value='-1'>暂无数据，请添加</option>");
                    }
                    else {
                        layer.alert(err.responseText);
                    }
                    //layer.msg(err.responseText, { icon: 2 });
                }
            })
        }

        //新增商品分类
        function AddGoodCong(aikeApplet_Goods) {
            $.ajax({
                type: 'post',
                url: '/GoodsConfigInfo/GoodsConfigInfo/AddGoodCongInformation',
                data: aikeApplet_Goods,
                dataType: "json",
                success: function (data) {
                    if (data.code = 200) {
                        $("#susses").append(data.info);
                    }
                }, error: function (err) {
                    if (err.status == 500) {
                        layer.alert(err.responseText);
                    }
                    //layer.msg(err.responseText, { icon: 2 });
                }
            })
        }
    </script>
</body>

